package com.sbox.db;

import android.database.sqlite.SQLiteDatabase;
import android.content.Context;
import com.sbox.model.NoteItem;
import com.sbox.model.SBoxConst;


public class ContentMgr {
	private DBHelper mDBHelper = null;
	private SQLiteDatabase mDatabase = null;
	private static ContentMgr mContentMgr = null;
	private NoteDAO mNoteDAO = new NoteDAO();
	
	private ContentMgr(Context context)
	{
		mDBHelper = new DBHelper(context, SBoxConst.DB_FILE_NAME);
		mDatabase = mDBHelper.getWritableDatabase();
	}
	
	public static ContentMgr getInstance(Context c)
	{
		if( mContentMgr == null )
		{
			mContentMgr = new ContentMgr(c);
			mContentMgr.mNoteDAO.setDatabase(mContentMgr.mDatabase);
		}
		
		return mContentMgr;
	}
	
	public NoteItem loadNote(long id)
	{
		return mNoteDAO.loadNote(id);
	}
	
	public NoteItem[] loadNoteTitles()
	{		
		return mNoteDAO.loadNoteTitles();
	}
	
	public NoteItem[] loadNotesAfter(long time) {
		return mNoteDAO.loadNotesAfter(time);
	}
	
	public void insertNote(NoteItem note)
	{
		mNoteDAO.insertNote(note);
	}
	
	public void updateNote(NoteItem note)
	{
		mNoteDAO.updateNote(note);
	}
	
	public void deleteNote(NoteItem note)
	{
		mNoteDAO.deleteNote(note);
	}
	
	public void deleteAllNotes()
	{
		mNoteDAO.deleteAllNotes();
	}
}
